package cn.itcast.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ScrollTest {
	
	public static void main(String[] args) throws SQLException {
		scroll();
	}
	
	static void scroll() throws SQLException {
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			conn = JdbcUtils.getConnection();
			st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
					ResultSet.CONCUR_READ_ONLY);

			rs = st.executeQuery("select id, name, money, birthday from user");

//			while (rs.next()) {
//				System.out.println(rs.getObject("id") + "\t"
//						+ rs.getObject("name") + "\t"
//						+ rs.getObject("birthday") + "\t"
//						+ rs.getObject("money"));
//			}
//			
//			System.out.println("------------------------------");
			rs.absolute(5);
			
			int i = 0;
			while (rs.next() && i < 10) {
				i++;
				System.out.println(rs.getObject("id") + "\t"
						+ rs.getObject("name") + "\t"
						+ rs.getObject("birthday") + "\t"
						+ rs.getObject("money"));
			}
			
		} finally {
			JdbcUtils.free(rs, st, conn);
		}
	}

}
